package org.lyl.taobao.controller;

import org.lyl.taobao.api.ICommodityService;
import org.lyl.taobao.service.CommodityServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: Re
 * @Date: 2021/4/5 11:28
 */
@WebServlet("/updateCommodity")
public class UpdateCommodityServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;utf-8");
        req.setCharacterEncoding("UTF-8");
        String c_Id = req.getParameter("c_Id");
        String c_Name = req.getParameter("c_Name");
        String c_Price = req.getParameter("c_Price");
        int id = Integer.valueOf(c_Id);
        float price = Float.valueOf(c_Price);
        ICommodityService iCommodityService = new CommodityServiceImpl();
        if (iCommodityService.updateCommodity(id,c_Name,price)) {
            req.setAttribute("msg","更改成功");
        } else {
            req.setAttribute("msg","更改失败");
        }
        req.getRequestDispatcher("updateCommodity.jsp").forward(req,resp);
    }
}
